<!DOCTYPE html>
<html>
  <head>
    <title>Dynamic Components Example</title>
    <script src="https://unpkg.com/vue@2"></script>
    <style>
      .tab-button {
        padding: 6px 10px;
        border-top-left-radius: 3px;
        border-top-right-radius: 3px;
        border: 1px solid #ccc;
        cursor: pointer;
        background: #f0f0f0;
        margin-bottom: -1px;
        margin-right: -1px;
      }
      .tab-button:hover {
        background: #e0e0e0;
      }
      .tab-button.active {
        background: #e0e0e0;
      }
      .tab {
        border: 1px solid #ccc;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <div id="dynamic-component-demo" class="demo">
      <button
        v-for="tab in tabs"
        v-bind:key="tab.name"
        v-bind:class="['tab-button', { active: currentTab.name === tab.name }]"
        v-on:click="currentTab = tab"
      >
        {{ tab.name }}
      </button>

      <component v-bind:is="currentTab.component" class="tab"></component>
    </div>

    <script>
      var tabs = [
        {
          name: "Home",
          component: {
            template: "<div>Home component</div>"
          }
        },
        {
          name: "Posts",
          component: {
            template: "<div>Posts component</div>"
          }
        },
        {
          name: "Archive",
          component: {
            template: "<div>Archive component</div>"
          }
        }
      ];

      new Vue({
        el: "#dynamic-component-demo",
        data: {
          tabs: tabs,
          currentTab: tabs[0]
        }
      });
    </script>
  </body>
</html>
